home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11405 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  37 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!mikenann
  3. From: Michael Glassman and Ann Ross <mikenann@netcom.com>
  4. Subject: Re: Can you overload a constructor?
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <3147CDA4.71BC@netcom.com>
  7. Sender: mikenann@netcom21.netcom.com
  8. Content-Transfer-Encoding: 7bit
  9. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  10. References: <Do859K.K9B@watserv3.uwaterloo.ca>
  11. Mime-Version: 1.0
  12. Date: Thu, 14 Mar 1996 07:41:24 GMT
  13. X-Mailer: Mozilla 2.0 (Win16; I)
  14.  
  15. jfournie@sciborg.uwaterloo.ca wrote:
  16. > Greetings,
  17. > I am new to C++ and just wanted to make sure it
  18. > was OK to overload a constructor.  gnu c++
  19. > doesn't have a problem with it, but is it normally
  20. > done?
  21.  
  22. Absolutely. Overloaded constructors are often desired.
  23. Consider a string class, String. We may want the following constructors:
  24.  
  25.     String( ); // A constructor with no arguments.
  26.                // Creates an empty String.
  27.     String( const char* const ); // Creates a String from a 
  28.                                  //C-style string.
  29.     String( const String& ); // Creates a copy of another String.
  30.                              // Also known as the copy contructor.
  31.     String( const int ); // Creates a String from an integer.
  32.  
  33. Michael Glassman
  34.